
//  class StatusCell: UITableViewCell { class StatusCell: UITableViewCell { StatusCell.swift
//  微博三天
//
//  Created by jessica on 15/11/15.
//  Copyright © 2015年 jessica. All rights reserved.


import UIKit
import SnapKit


let StatusCellMargin: CGFloat = 12
let StatusCellIconWitdth: CGFloat = 35

class StatusCell: UITableViewCell {
    
    
    //记录底部约束 根据是否有配图进行动态修改
//    
    var bottomConstraints : Constraint?
//
//    //数据模型
//    
    var status : Status?{
//
        didSet{
//            //原创微博的数据模型
            originalView.sta = status
//
//            //移除底部约束
            self.bottomConstraints?.uninstall()
//
//            //转发微博的数据模型
            if let retweet = status?.retweeted_status
            {
                retweetedView.retweetedStatus = retweet
//            //设置显示
                retweetedView.hidden = false//显示(不隐藏)
//
        //这里是bottonView其他地方写的是对应的self
                
               bottomView.snp_makeConstraints(closure: { (make) -> Void in

self.bottomConstraints = make.top.equalTo(retweetedView.snp_bottom).offset(StatusCellMargin).constraint
                    
                })
            }else{
                
                retweetedView.hidden = true
                
                bottomView.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomConstraints = make.top.equalTo(originalView.snp_bottom).offset(StatusCellMargin).constraint

                })
                
            }
 
        }
        
    }
    
        
        

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .None
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //    //设置UI
    private func setupUI(){
        //    //添加子控件
        //原创基本视图
        contentView.addSubview(originalView)
        //底部视图
        contentView.addSubview(bottomView)
        //转发微博部分
        contentView.addSubview(retweetedView)
        //
        //        //设置原创基本视图约束信息
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView.snp_top)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            //            make.height.equalTo(50)
            //这里也是一个重点
            
        }
        //   设置底部视图约束信息
        bottomView.snp_makeConstraints { (make) -> Void in
            
//            make.top.equalTo(retweetedView.snp_bottom)
            self.bottomConstraints = make.top.equalTo(retweetedView.snp_bottom).constraint
            
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.height.equalTo(40)
        }
        
        
        //文本text自适应行高的约束
        
        contentView.snp_makeConstraints { (make) -> Void in
            //            contentView对底部的约束很关键
            //            make.bottom.equalTo(originalView.snp_bottom)
            make.bottom.equalTo(bottomView.snp_bottom)
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
        }
        
        //转发微博部分的约束
        retweetedView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(originalView.snp_bottom)
            make.left.equalTo(originalView.snp_left)
            make.right.equalTo(originalView.snp_right)
            
        }
        
    }
    //    //懒加载数据
    //原创微博的基本视图
    private lazy var originalView :StatusOriginalView = StatusOriginalView()
    //评论等底部视图
    private lazy var bottomView : StatusCellBottomView = StatusCellBottomView()
    
    //转发微博的字段
    private lazy var retweetedView :ReweetedStatusView = ReweetedStatusView()
    
    
}

